package com.szf.mywiki.controller;

import com.szf.mywiki.domain.Test;
import com.szf.mywiki.service.TestService;
import com.szf.mywiki.util.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class TestController {

    private static final Logger LOG = LoggerFactory.getLogger(TestController.class);

    @Resource
    private TestService testService;

    @Autowired
    private RedisUtil redisUtil;

    @GetMapping("/hello")
    public String hello() {
        return "Hello,World";
    }

    @GetMapping("/test")
    public List<Test> test() {
        return testService.getTests();
    }

    @RequestMapping("/redis/set/{key}/{value}")
    public String set(@PathVariable Long key, @PathVariable String value) {
        redisUtil.set(key.toString(), value, 3600);
        LOG.info("key:{},value:{}", key, value);
        return "success";
    }

    @RequestMapping("redis/get/{key}")
    public Object get(@PathVariable Long key) {
        Object o = redisUtil.get(key.toString());
        LOG.info("key:{},value:{}", key, o);
        return o;
    }

}
